<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout">
<head>
    <title>微信支付</title>
</head>
<body>
    <div style="display: none;">
        <input id="appId" th:value="${appId}"/>
        <input id="timeStamp" th:value="${timeStamp}"/>
        <input id="nonceStr" th:value="${nonceStr}"/>
        <input id="info_package" th:value="${info_package}"/>
        <input id="signType" th:value="${signType}"/>
        <input id="sign" th:value="${sign}"/>
    </div>
    <div data-th-replace="layout/footer"></div>
    <script type="text/javascript">
        var appId = document.getElementById("appId").value;
        var timeStamp = document.getElementById("timeStamp").value;
        var nonceStr = document.getElementById("nonceStr").value;
        var info_package = document.getElementById("info_package").value;
        var signType = document.getElementById("signType").value;
        var sign = document.getElementById("sign").value;
        function onBridgeReady(){
            var params = {
                "appId":appId,     //公众号名称，由商户传入
                "timeStamp":timeStamp,         //时间戳，自1970年以来的秒数
                "nonceStr":nonceStr, //随机串
                "package":info_package,
                "signType":signType,         //微信签名方式：
                "paySign":sign //微信签名
            };
            WeixinJSBridge.invoke('getBrandWCPayRequest',params,function(res){
                    // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
                    if(res.err_msg == "get_brand_wcpay_request:ok" ) {
                        alert("订单支付成功");
                        window.location.href= baseloaction + '/mobile/uc/order/orderList';
                    }else{
                        //alert(res.err_msg);
                        if(res.err_msg=='get_brand_wcpay_request:cancel'){
                            alert("订单取消支付");
                            window.location.href= baseloaction + '/mobile/uc/order/orderList';
                        }
                    }
                }
            );
        }
        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            }
        }else{
            onBridgeReady();
        }
    </script>
</body>
</html>
